package com.example.minzhengtong.ui

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.text.style.StyleSpan
import com.example.minzhengtong.MyApp
import com.example.minzhengtong.R
import com.example.minzhengtong.base.BaseA
import com.example.minzhengtong.databinding.ActivityAuthBinding

class AuthA : BaseA() {

    companion object{
        fun enterThis(context : Context,tag : Int){
            val intent = Intent(context,AuthA::class.java)
            intent.putExtra("tag",tag)
            context.startActivity(intent)
        }
    }

    private lateinit var binding : ActivityAuthBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityAuthBinding.inflate(layoutInflater)
        setContentView(binding.root)

        initTitle("信息授权")

        val str1 = "为能正常使用服务，系统将会收集并向第三方分享您的"
        val str2 = "相关信息，请务必确认信息的准确性。"
        val str3 = "现请您授权服务使用您本人的信息。"


        val spannableString = SpannableString(str1+str2+str3)

        spannableString.setSpan(ForegroundColorSpan(resources.getColor(R.color.main,)),str1.length,str1.length + str2.length,SpannableString.SPAN_EXCLUSIVE_INCLUSIVE)
        spannableString.setSpan(StyleSpan(android.graphics.Typeface.BOLD),str1.length,str1.length + str2.length,SpannableString.SPAN_EXCLUSIVE_INCLUSIVE)

        binding.hint.text = spannableString

        initListener()

    }

    private fun initListener(){
        binding.deny.setOnClickListener {
            finish()
        }
        binding.auth.setOnClickListener {
            if (binding.checkbox.isChecked){
                when(intent!!.getIntExtra("tag",0)){
                    0 -> {
                        SocialInsuranceA.enterThis(baseContext)
//                        SocialInsuranceC.enterThis(baseContext)
                    }
                    1 -> {
                        MedicalInsuranceA.enterThis(baseContext)
                    }
                    9 -> {
                        GJJServiceA.enterThis(baseContext)
                    }
                    else -> {
                        GJJServiceA.enterThis(baseContext)
                    }
                }
                MyApp.isAuth = true
                finish()
            }else{
                showToast("请先同意授权")
            }
        }
    }

}